package cn.falconnect.adserver.adapter.persistence.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import cn.falconnect.adserver.domain.ad.CreativeGroup;

@Component
public interface CreativeGroupDao {
	
	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "name", property = "name"),
			@Result(column = "campaign_id", property = "campaignId"),
			@Result(column = "status", property = "status"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime"),
	})
	@Select("select * from creative_group ")
	List<CreativeGroup> findAll();
	
	
	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "name", property = "name"),
			@Result(column = "campaign_id", property = "campaignId"),
			@Result(column = "status", property = "status"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime"),
	})
	@Select("select * from creative_group where id = #{id} and status = #{status}")
	CreativeGroup selectById(@Param("id")long id, @Param("status")int status);
	
	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "name", property = "name"),
			@Result(column = "campaign_id", property = "campaignId"),
			@Result(column = "status", property = "status"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime"),
	})
	@Select("select g.* from creative_group as g,creative_group_creative_map as map where g.id = map.creative_group_id and g.status =1 and map.creative_id=#{creativeId}")
	CreativeGroup selectByCreativeId(@Param("creativeId")long creativeId);

}
